class TokenInfo {
    constructor(db) {
      this.db = db;
    }
  
    async createTable() {
      const sql = `
        CREATE TABLE IF NOT EXISTS token_info (
          name TEXT PRIMARY KEY,
          address TEXT,
          accuracy INTEGER,
          remark TEXT,
          mint_address TEXT
        );
      `;
      await this.db.query(sql);
      console.log('TokenInfo table created.');
    }
  
    async insert(name, address, accuracy, remark, mint_address) {
      const sql = 'INSERT INTO token_info (name, address, accuracy, remark, mint_address) VALUES (?, ?, ?, ?, ?)';
      const tokenId = await this.db.insert(sql, [name, address, accuracy, remark, mint_address]);
      return tokenId;
    }
  
    async getByName(name) {
      const sql = 'SELECT * FROM token_info WHERE name = ?';
      const tokens = await this.db.query(sql, [name]);
      return tokens[0];
    }
  
    async getAll() {
      const sql = 'SELECT * FROM token_info';
      return await this.db.query(sql);
    }
  
    async update(name, address, accuracy, remark, mint_address) {
      const sql = 'UPDATE token_info SET address = ?, accuracy = ?, remark = ?, mint_address = ? WHERE name = ?';
      const changes = await this.db.update(sql, [address, accuracy, remark, mint_address, name]);
      return changes;
    }
  
    async delete(name) {
      const sql = 'DELETE FROM token_info WHERE name = ?';
      const changes = await this.db.delete(sql, [name]);
      return changes;
    }
  }
  module.exports = TokenInfo;